package com.cskaoyan.service;

import com.cskaoyan.mapper.OrderGoodsMapper;
import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.vo.GoodsStatVO;

import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.vo.OrderStatVO;

import com.cskaoyan.vo.UserStatVO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;


@Service
public class StatisticalStatementsServiceImpl implements StatisticalStatementsService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    private OrderGoodsMapper orderGoodsMapper;

    @Autowired
    OrderMapper orderMapper;

    /**
     * 订单统计
     * @return
     */
    @Override
    public OrderStatVO getOrderStat() {
        List<OrderStatVO.RowsBean> rowsBeans = orderMapper.groupByAddTime();
        OrderStatVO orderStatVO = new OrderStatVO();
        ArrayList<String> strings = new ArrayList<>();
        strings.add("day");
        strings.add("orders");
        strings.add("customers");
        strings.add("amount");
        strings.add("pcr");
        orderStatVO.setColumns(strings);
        orderStatVO.setRows(rowsBeans);
        return orderStatVO;
    }

    /**
     * 用户统计
     * @return
     */
    @Override
    public UserStatVO getUserStat(){
        List<UserStatVO.RowsBean> rowsBeans = userMapper.groupByAddTime();

        UserStatVO userStatVO = new UserStatVO();
        ArrayList<String> strings = new ArrayList<>();
        strings.add("day");
        strings.add("users");
        userStatVO.setColumns(strings);
        userStatVO.setRows(rowsBeans);
        return userStatVO;
    }


    @Override
    public GoodsStatVO getGoodsStat() {
        List<GoodsStatVO.RowsBean> rowsBeanList = orderGoodsMapper.selectGroupByAddTime();


        GoodsStatVO goodsStatVO = new GoodsStatVO();
        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("products");
        columns.add("amount");
        goodsStatVO.setRows(rowsBeanList);
        goodsStatVO.setColumns(columns);
        return goodsStatVO;
    }

}
